package com.ziyun.erp.web.modules.bonusRule.controller;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.bonusRule.entity.SellerBonusRuleEntity;
import com.ziyun.erp.modules.bonusRule.service.SellerBonusRuleService;
import com.ziyun.erp.modules.capital.service.MerchantOrderAccountService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * 奖励金规则
 * （已废弃使用，gz 2018.12.10）
 * @author zh
 * @email 
 * @date 2018-11-29 17:59:28
 */
@RestController
@RequestMapping("bonusRule/sellerbonusrule")
public class SellerBonusRuleController {
    @Autowired
    private SellerBonusRuleService sellerBonusRuleService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("bonusRule:sellerbonusrule:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sellerBonusRuleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("bonusRule:sellerbonusrule:info")
    public R info(@PathVariable("id") Integer id){
        SellerBonusRuleEntity sellerBonusRule = sellerBonusRuleService.selectById(id);

        return R.ok().put("sellerBonusRule", sellerBonusRule);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("bonusRule:sellerbonusrule:save")
    public R save(@RequestBody SellerBonusRuleEntity sellerBonusRule){
        sellerBonusRule.setCreater(UserUtils.getCurentUser().getUsername());
        sellerBonusRule.setCreaterTime(new Date());
        sellerBonusRuleService.saveBonusRule(sellerBonusRule);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("bonusRule:sellerbonusrule:update")
    public R update(@RequestBody SellerBonusRuleEntity sellerBonusRule){
        sellerBonusRuleService.updateBonusRule(sellerBonusRule);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("bonusRule:sellerbonusrule:delete")
    public R delete(@RequestBody Integer[] ids){
        List<SellerBonusRuleEntity> sellerBonusRuleList = new ArrayList<>();
        for (Integer id : ids ){
            SellerBonusRuleEntity temp = new SellerBonusRuleEntity();
            temp.setId(id);
            temp.setDelFlag(1);
            sellerBonusRuleList.add(temp);
        }
        sellerBonusRuleService.updateBatchById(sellerBonusRuleList);

        return R.ok();
    }

}
